package dao

import (
	"family/model"
	"family/pkg/db"
)

var EventDao = new(eventDao)

type eventDao struct{}

func (*eventDao) Create(event *model.Event) error {
	event.ID = db.GetId()
	return db.DB.Create(&event).Error
}

func (*eventDao) Page(people uint64) ([]*model.Event, int64, error) {
	var event []*model.Event
	var total int64
	result := db.DB.Where(&model.Event{People: people}).Find(&event)
	if result.Error != nil {
		return nil, 0, result.Error
	}
	return event, total, nil
}

func (*eventDao) Info(id string) (*model.Event, error) {
	var event model.Event
	err := db.DB.First(&event, id).Error
	if err != nil {
		return nil, err
	}
	return &event, nil
}

func (*eventDao) Update(event *model.Event) error {
	return db.DB.Model(&event).Updates(&event).Error
}

func (*eventDao) Delete(ids []string) error {
	var event model.Event
	return db.DB.Delete(&event, ids).Error
}
